package com.anytron.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.anytron.base.service.impl.BaseServiceImpl;
import com.anytron.mapper.AppApolloMapper;
import com.anytron.mapper.AppInfoMapper;
import com.anytron.model.AppApollo;
import com.anytron.model.AppInfo;
import com.anytron.model.req.PageRequest;
import com.anytron.service.AppApolloService;
import com.github.pagehelper.PageInfo;

import tk.mybatis.mapper.entity.Example;

@Service
public class AppApolloServiceImpl extends BaseServiceImpl<AppApollo> implements AppApolloService {
	
	@Autowired
	AppInfoMapper appInfoMapper;
	@Autowired
	public void setMapper(AppApolloMapper mapper) {
		this.mapper = mapper;
	}

	@Override
	public PageInfo<AppApollo> queryDataByPage(PageRequest pageRequest,AppApollo appApollo) {
		Example example=new Example(AppApollo.class);
	    Example.Criteria criteria=example.createCriteria();
	    example.setOrderByClause("app_id asc");
	    if (appApollo.getAppId()!=null && appApollo.getAppId() > 0) {
	    	criteria.andEqualTo("appId", appApollo.getAppId());
		}
	    if (StringUtils.isNotBlank(appApollo.getApolloAppId())) {
	    	criteria.andLike("apolloAppId", "%"+appApollo.getApolloAppId()+"%");
	    }
		PageInfo<AppApollo> pageInfo = pageByExample(pageRequest, example);
		pageInfo.getList().forEach(item->{
			AppInfo appInfo = appInfoMapper.selectByPrimaryKey(item.getAppId());
			if (appInfo!=null) {
				item.setAppName(appInfo.getAppName());
			}
		});
		return pageInfo;
	}

}
